package academic.ui.client.util;


import java.util.Date;

import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.ui.Image;

import ecommerce.soco.shared.GWT_Customer;

public class ClientHelper {

	
	public static Image createImage(String src,Double ratio,Integer width) {
		Image img = new Image(src);
		img.setSize(String.valueOf(width)+"px",String.valueOf(ratio*width)+"px");
		return img;
	}
	
	public static String getImageURL(String userImg,Integer userid,String objectType) {
		return homeDir+"PICS/"+objectType+"/"+String.valueOf(userid)+"/"+userImg;
	}
	
	public static String formatPrice(Double price) {
		return NumberFormat.getCurrencyFormat().format(price).substring(2);
	}
	
	public static String formatPriceNoDecimal(Double price) {
		String p = formatPrice(price);
		return p.substring(0, p.length()-3);
	}
	
	public static String formatDate(Date d) {
		return DateTimeFormat.getShortDateFormat().format(d);
	}
	
	public static String formatDateTime(Date d) {
		return DateTimeFormat.getShortDateTimeFormat().format(d);
	}
	
	public static String homeDir = GWT.getModuleBaseURL()+"../";

	public static String getCustomerPhotoURL(GWT_Customer customer) {
		if(customer!=null && customer.getPhoto()!=null)
		{
			return getImageURL(customer.getPhoto(),customer.getId(),"Users");
		}
		else
			return DEFAULT_USER_PHOTO;
			
	}
	
	public static String DEFAULT_USER_PHOTO=GWT.getModuleBaseURL()+"images/blue_ghost.jpg";

	public static String ellipsify(String name, int i) {
		if(i<name.length())
			return name.substring(0,i)+"...";
		return name;
	}

}
